package com.remon.quartz.service.impl;

import com.remon.quartz.controller.restfule.Response;
import com.remon.quartz.dao.CustomerResp;
import com.remon.quartz.entity.Customer;
import com.remon.quartz.service.CustomerService;
import com.remon.quartz.vo.CustomerReq;
import github.remonlong.restfulutil.exception.RestfulResultUtil;
import github.remonlong.restfulutil.exception.Result;
import github.remonlong.restfulutil.exception.api.BadApiException;
import github.remonlong.restfulutil.exception.enumeration.EnumResult;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 客户端逻辑处理类
 *
 * @author remon
 * @create 2018-08-15 23:33
 **/
@Slf4j
@Service
public class CustomerServiceImpl implements CustomerService {

    /**
     * 消费者端数据库链接对象
     */
    private final CustomerResp customerResp;

    @Autowired
    public CustomerServiceImpl(CustomerResp customerResp) {
        this.customerResp = customerResp;
    }

    /**
     * 校验传输内容是否正确
     * @param customerReq @link { CustomerReq }
     * @return @link {Response}
     * @throws Exception
     */
    @Override
    public Customer findByAppid(CustomerReq customerReq) throws Exception {
        Customer customer = customerResp.findByAppid(customerReq.getAppid());

        if (customer == null) {
            throw new BadApiException(EnumResult.PARAM_VALID_ERROR);
        }

        if (!customerReq.getAppsecret().equals(customer.getAppsecret())) {
            throw new BadApiException(EnumResult.PARAM_VALID_ERROR);
        }

        return customer;
    }



   /* @Override
    public Response save(Customer customer) {
        return customerResp.save(customer);
    }*/
}
